"""
面向过程
ATM机存取款功能
ATM角色
用户角色
1.先登录
2.菜单界面
	存款
		用户的账户金额减少了500
	取款
		用户的账户金额增加了500块
	查询
		用户的账户金额显示
"""

#面向过程

def regist():
    user = input("请输入你要注册的用户名:")
    while True:
        passwd = input("请设置你的密码:")
        passwd1 = input("请确认你的密码:")

        if passwd != passwd1:
            print("\033[31m两次密码不一致！请重新设置密码\033[0m")
            continue
        else:
            break
    users[user] = passwd
    balance[user] = 0
    print(f"注册成功！欢迎你{user}")


def login(admin,passwd):
    # 声明谁在登录
    global using
    if (admin,passwd) in users.items():
        using = admin
        return True
    else:
        return False

#取钱
def withdrawal(money_out):
    if int(money_out) > balance[using]:
        return "账户余额不足"
    else:
        if ATM_balance < int(money_out):
            return "ATM储钞量不足"
        else:
            balance[using] = balance[using] - int(money_out)
            return "取款成功"
#存钱
def deposit():
    global ATM_balance
    balance[using] = balance[using] + int(money_in)
    ATM_balance  += int(money_in)
    print(f"成功存入{money_in}元")

#查询余额
def check():
    print(f"亲爱的{using}，您的账户余额为：{balance[using]}元")

#退出函数
def process_finished():
    import os
    print("您已退出程序")
    os._exit(0)

#================================================
users = {"caojw":"654321"}
balance = {"caojw":10000000}
ATM_balance = 100000
#================================================
#一级菜单
while True:
    print("\033[32m南风银行24hATM~\033[0m")
    print("\033[32m==================================================\033[0m")
    print("\033[31m外部操作栏\033[0m                                  |")
    print("\033[32m==================================================\033[0m")
    print("1.登录 2.注册 3.退出程序")
    option_button_one = input("请输入您要执行的操作:")
    if option_button_one == "1":
        admin = input("请输入您的用户名：")
        passwd = input("请输入您的密码：")
        if login(admin,passwd):
            print("登录成功！")
            break
        else:
            print("用户名或者密码错误，登陆失败")
            continue

    elif option_button_one == "2":
        regist()

    elif option_button_one == "3":
        process_finished()

    else:
        print("\033[31m请输入可选的选项数字！\033[0m")
        continue

#二级菜单
while True:
    print("\033[32m南风银行24hATM~\033[0m")
    print("\033[32m==================================================\033[0m")
    print("\033[31m内部操作栏\033[0m                                  |")
    print("\033[32m==================================================\033[0m")
    print("1.存款 2.取款 3.查询余额 4.退出程序")
    option_button_two= input("请输入您要执行的操作:")

    if option_button_two == "1":
        money_in = input("请输入你要存款的金额:")
        if money_in.isdigit():
            deposit()
        else:
            print("请合法输入！")

    elif option_button_two == "2":
        money_out = input("请输入你要取款的金额:")
        if money_out.isdigit():
            bool_value = withdrawal(money_out)
            if bool_value == "ATM储钞量不足":
                print("很抱歉，该ATM储钞量不足，系统已自动取消本次业务，如需帮助，请拨打工作人员电话\"188-9031-4631\"")
            elif bool_value == "取款成功":
                print(f"您已成功取出{money_out}元")
            else:
                print("您的账户余额不足，取款失败")
        else:
            print("请合法输入！")


    elif option_button_two == "3":
        check()

    elif option_button_two.upper() == "4":
        process_finished()

    else:
        print("\033[31m请输入可选的选项数字！\033[0m")
        continue
